local Lua__bala = fk.CreateSkill {
  name = "Lua__bala",
}

Fk:loadTranslationTable {
  ["Lua__bala"] = "扒拉",
  [":Lua__bala"] = "当其他角色获得你牌时，你可以弃置一名角色区域内至多四张牌，若你以此法弃置的牌中存在花色相同的牌，其视为对你使用一张【杀】。",
  ["#bala-target"] = "扒拉：选择一名角色，弃置其区域内的至多四张牌",
}

Lua__bala:addEffect(fk.AfterCardsMove, {
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(Lua__bala.name) then return false end
    for _, move in ipairs(data) do
      if move.from == player and move.to and move.to ~= player and move.toArea == Card.PlayerHand then
        return true
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function(p)
      return not p:isAllNude()
    end)
    if #targets == 0 then return false end
    local to = room:askToChoosePlayers(player, {
      targets = targets,
      min_num = 1,
      max_num = 1,
      prompt = "#bala-target",
      skill_name = Lua__bala.name,
      cancelable = true,
    })
    if #to > 0 then
      event:setCostData(self, { target = to[1] })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).target
    local card = room:askToChooseCards(player, {
      min = 1,
      max = 4,
      target = to,
      flag = "hej",
      skill_name = Lua__bala.name,
    })
    room:throwCard(card, Lua__bala.name, to, player)
    if table.find(card, function(id) return #table.filter(card, function (id2)
      return Fk:getCardById(id).suit == Fk:getCardById(id2).suit end) > 0 end)then
      room:useVirtualCard("slash", nil, to, {player}, Lua__bala.name)
    end
  end,
})


return Lua__bala
